<template>
  <div style="padding:20px 20px 20px 20px;">
    <el-row >
      <el-button type="success" plain @click="goBack">返回</el-button>
      <el-button type="primary" plain @click="printReport">打印</el-button>
    </el-row>
    <div id="printContent">
      <component :is="currentView" :date="printDate" :propReportId="reportId"  :propName="agencyinfo.cName" :propLicense="agencyinfo.licence" @pickFatherFounction="pickFatherFounction"></component>
    </div>
    
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import vPrintWljd from "../components/PrintWljd.vue";
import vPrintZzcj from "../components/PrintZzcj.vue";
import vPrintZzjd from "../components/PrintZzjd.vue";
export default {
  components: {
    vPrintWljd,
    vPrintZzcj,
    vPrintZzjd
  },
  // beforeRouteEnter(to, from, next) {
  //   next(vm => {
      
  //     sessionStorage.setItem("printDate", to.params.date ? to.params.date : "");
  //     sessionStorage.setItem("printtype", to.params.type ? to.params.type : 0);
  //     sessionStorage.setItem(
  //       "reportId",
  //       to.params.reportId ? to.params.reportId : ""
  //     );
  //   });
  // },
  computed: {
    ...mapGetters(["reportDetail", "agencyinfo"]),
    printtype() {
      return parseInt(sessionStorage.getItem("printtype"));
    },
    printDate() {
      return sessionStorage.getItem("printDate");
    },
    reportId() {
      return parseInt(sessionStorage.getItem("reportId"));
    },
    currentView() {
      let currentView = "";
      switch (this.printtype) {
        case 0:
          currentView = "vPrintWljd";
          break;
        case 1:
          currentView = "vPrintZzjd";
          break;
        case 2:
          currentView = "vPrintZzcj";
          break;
        default:
          currentView = "vPrintZzcj";
          break;
      }
      return currentView;
    }
  },
  mounted(){
    console.log(sessionStorage.getItem("reportId"))
  },
  methods: {
    pickFatherFounction() {
      return true;
    },
    goBack() {
      this.$router.go(-1);
    },
    printReport() {
      var oldContent = $("body").html();
      $("body").html($("#printContent").html());
      window.print();
      $("body").html(oldContent);
    }
  }
};
</script>
<style>

</style>

